package com.project.baowei.prsenter;

import android.annotation.SuppressLint;
import android.content.Intent;

import com.project.baowei.bean.request.LoginRequest;
import com.project.baowei.bean.respoes.LoginBean;
import com.project.baowei.contract.LoginContract;
import com.project.baowei.net.NetUtils;
import com.project.baowei.ui.HomeActivity;
import com.project.baowei.utils.UserUtils;
import com.wangshen.base.app.AppActivityKey;
import com.wangshen.base.net.bean.BaseAppEntity;
import com.wangshen.base.net.interceptor.ExCookieInterceptor;
import com.wangshen.base.ui.mvp.base.presenter.BasePresenter;

import io.reactivex.functions.Consumer;

public class LoginPresenter  extends BasePresenter<LoginContract.View> implements LoginContract.Presenter {
    @Override
    public void signIn(LoginRequest body) {
        NetUtils.geApi().signIn(body)
                .compose(this.handleEverythingResult())
                .subscribe(new Consumer<BaseAppEntity<LoginBean>>() {
                    @Override
                    public void accept(@SuppressLint("CheckResult") BaseAppEntity<LoginBean> loginBeanBaseAppEntity) throws Exception {
                        ExCookieInterceptor.TOKEN=loginBeanBaseAppEntity.getData().getToken();
                        UserUtils.getInstance().setUserBean(loginBeanBaseAppEntity.getData());
                        getView().showMessage(loginBeanBaseAppEntity.getMessage());
                        getView().onSuccess();
                    }
                }, new Consumer<Throwable>() {
                    @Override
                    public void accept(Throwable throwable) throws Exception {
                        getView().showMessage(throwable.getMessage());
                    }
                });
    }
}
